// components/book-comment/book-comment.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    updataTime: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setUpdateTime() {
      let time = this.properties.list.create_time
      let num = parseInt((Date.now() - (time * 1000)) / 1000 / 60 / 60)
      if (num > 24) {
        let data = new Date(time * 1000)
        let y = data.getFullYear()
        let M = data.getMonth() + 1 >= 10 ? data.getMonth() + 1 : '0' + (data.getMonth() + 1)
        let d = data.getDate() >= 10 ? data.getDate() : '0' + data.getDate()
        num = `${y}-${M}-${d}`
      } else {
        num = num + '个小时前'
      }

      this.setData({
        updataTime:num
      })

    },
  },


  lifetimes:{
    ready:function () {
      this.setUpdateTime()
    }
  }
})
